import jwt

#对用户敏感信息进行编码 
encode_jwt = jwt.encode({'uid':'1'},'123',algorithm='HS256')

print(encode_jwt)
#转码
encode_jwt = str(encode_jwt,'utf-8')
print(encode_jwt)

#解密
decode_jwt = jwt.decode('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIxIn0.1mZqIWGT-p2bMfmLsoIJeVwAB5NArMz-RQYBjiLzsv0','123',algorithms=['HS256'])

print(decode_jwt)

#设置过期时间
import datetime

#设置载荷
playload = {
    
    'exp':int((datetime.datetime.now()+datetime.timedelta(seconds=20)).timestamp()),
    'data':{'uid':'2'}
    
}

#加密
encode_time = jwt.encode(playload,'123',algorithm="HS256")
print(encode_time)

decode_time = jwt.decode('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1Nzc5NDUzMTIsImRhdGEiOnsidWlkIjoiMiJ9fQ.9Itnxd5M0IElWmEHE-LWIdu9uFGXp0tWZrz1aymBl8Q','123',algorithms=['HS256'])

print(decode_time)